let defaultValue = {
  visible: false,
  text: '',
  type: ''
};
let timer = null;
export default {
  namespaced: true,
  state: { ...defaultValue },
  mutations: {
    modify(state, val) {
      state.visible = val.visible;
      state.text = val.text;
      state.type = val.type;
    }
  },
  actions: {
    showToast(context, payload) {
      context.commit('modify', { ...payload, visible: true });

      if (timer) {
        clearTimeout(timer);
      }

      timer = setTimeout(() => {
        context.commit('modify', { ...context.state, visible: false });
      }, payload.duration || 2000)
    }
  }
}